package ch9sorting;

import java.awt.Point;

public class Ex6 {

	static Point FindElem(int[][] mat, int elem, int m, int n) {
		int i=0, j=n-1;
		while (i < m && j >= 0) {
			int matij = mat[i][j];
			if (matij == elem) {
				Point p = new Point(i, j);
				return p;
			}
			else if (matij > elem) {
				j--;
			}
			else {
				i++;
			}
			
		}
		return null;
	}

	public static void main(String ...strings) {
		int [][] mat = new int [][] {{1, 4, 7, 10}, {2, 5, 8, 11}, {3, 6, 9, 12}};
		Point findElem = FindElem(mat, 5, 3, 4);
		System.out.print(findElem);
	}
}
